<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>{BEESCRM:$title}</title>
    <meta name="description" content="">
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui, user-scalable=no">
    <meta http-equiv="cleartype" content="on">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/assets/base/busbooking/css/style.css">
    <link rel="stylesheet" href="/assets/base/busbooking/css/mobiscroll.custom-3.0.0-beta2.min.css">
    <link rel="stylesheet" href="/assets/base/busbooking/css/layer.css">
</head>
<body>
<div class="wraper">
    <form id="imgform" method="post" enctype="multipart/form-data">
        <div class="header">
            <div class="flex-between">
                <a href="/Base/Center/center/apply_id/{BEESCRM:$applyId}/account_id/{BEESCRM:$account_id}" class="iconfont icon-llmainpageback "></a>

                <div class="title text-center font-16">公交专线订票</div>
                <a href="/Base/BusBooking/history/apply_id/{BEESCRM:$applyId}" class="iconfont icon-lishijilu "></a>
            </div>
<!--            <div class="head-img">
                <img src="{BEESCRM:$imginfo}" class="clip-img" alt="">
            </div>
            <input type="file" id="file1" name="imgs1" onchange="showPreview(this)" class="upload-img hide">
            <input type="hidden" id="user_id" name="user_id" value="{BEESCRM:$user_id}" style="...">-->
            <div class="head-img relative_" id="portrait-wraper">
                <img src="{BEESCRM:$imginfo}" class="clip-img" alt="">
                <input type="file" id="file" class="upload-img" name="upload-img" id="upload-img" />
            </div>
            <div class="photoClip" id="photoClip">
                <div class="header clearfix">
                    <div class="flex-between">
                        <a href="/Base/Center/center/apply_id/{BEESCRM:$applyId}/account_id/{BEESCRM:$account_id}" class="iconfont icon-llmainpageback "></a>
                        <div class="title text-center font-16">{BEESCRM:$title}</div>
                        <a href="#" class="pull-right text-right save" id="edit-btn">完成</a>
                    </div>
                </div>

                <!--图片加载-->
                <div id="photoClip-wrapper">
                    <div class="lazy_tip" id="lazy_tip"><span>1%</span><br>	载入中......</div>
                    <div class="lazy_cover"></div>
                    <div class="pic_edit">
                        <div id="clipArea"></div>
                    </div>
                    <img src="" fileName="" id="hit">
                </div>

            </div>
        </div>
    </form>

    <div class="content">
        <div class="list gray2">
            <select name="" id="address1">
                <option value="">请选择出发地</option>
                <volist name="address" id="vo">
                    <option value="{BEESCRM:$vo.address_id}">
                        {BEESCRM:$vo.address_detail}
                    </option>
                </volist>
            </select>

            <div class="iconfont icon-chevron-copy-copy-copy"></div>
        </div>
        <div class="list gray2">
            <select name="" id="address2">
                <option value="">请选择目的地</option>
                <volist name="address" id="vo">
                    <option value="{BEESCRM:$vo.address_id}">
                        {BEESCRM:$vo.address_detail}
                    </option>
                </volist>
            </select>

            <div class="iconfont icon-chevron-copy-copy-copy"></div>
        </div>
        <div class="list gray2">
            <div>
                <input id="time" type="text" placeholder="请选择乘车日期" value="">
            </div>
            <div class="iconfont icon-chevron-copy-copy-copy"></div>
        </div>
    </div>
    <a href="#" class="btn text-center font-16 demand">查询</a>
</div>
</body>
<script src="/assets/base/busbooking/js/public.js"></script>
<script src="/assets/base/busbooking/js/layer.js"></script>
<script src="/assets/base/busbooking/js/jquery-2.1.0.min.js"></script>
<script src="/assets/base/busbooking/js/mobiscroll.custom-3.0.0-beta2.min.js"></script>
<script src="/assets/base/userCenter/static/publicjs/iscroll-zoom.js"></script>
<script src="/assets/base/userCenter/static/publicjs/jquery.photoClip.js"></script>
<script>
    photoClipInterfaceInit(
        "#photoClip",
        "#edit-btn",
        "#head-ortrait",
        "#portrait-wraper");

    var height = $(window).height();
    $('.wraper').css('minHeight', height);

//    function showPreview(source) {
//
//        var file = source.files[0];
//        if (window.FileReader) {  //当浏览器支持fileReader
//            var fr = new FileReader();
//            fr.onloadend = function (e) {
//                var img = document.createElement("img");
//                img.onerror = null;
//                img.src = e.target.result;
//                img.alt = '';
//                img.id = 'pic';
//                //$("#portrait").attr('src', e.target.result);
//                $('.clip-img').attr('src', e.target.result);
//            };
//            fr.readAsDataURL(file);
//        }
    $('#edit-btn').click(function () {
        var data = {};
        //var form = new FormData(document.getElementById("imgform"));
        data.picture = $("#file").attr('value');
        //删除字符串前的提示信息 "data:image/png;base64,"
        data.picture = data.picture.substring(22);
        $.ajax({
            type:'post',
            dataType: "json",
            data: data,
            url: '/Base/BusBooking/generatePicture/apply_id/{BEESCRM:$apply_id}',
            success: function (result) {
                if (result.status == 'S') {
                    fm.alert('上传成功');
                    // window.location.href = "/Base/BusBooking/demand/apply_id/{BEESCRM:$apply_id}";
                } else {
                    fm.alert('上传失败');
                    reload();
                }
            }
        })
//    }
    })

    $('.btn').click(function () {
        var address1=$("#address1 option:selected").val();
        var address2=$("#address2 option:selected").val();
        var time = $('#time').val();
        //time = (Date.parse(new Date(time)))/1000-28800;
        if(!address1){
            fm.alert('请选择发车地点')
            return;
        }
        if(!address2){
            fm.alert('请选择目的地')
            return;
        }
        if(!time){
            fm.alert('请选择乘车时间')
            return;
        }
        if(address1==address2){
            fm.alert('发车点和目的地不能相同')
            return;
        }
        $.ajax({
            url: '/Base/BusBooking/lookBus/apply_id/{BEESCRM:$apply_id}',
            data: { "start_id":address1 ,'end_id':address2,'bus_time':time},
            dataType: "json",
            type: "POST",
            traditional: true,
            success: function (result) {
                if (result.status == 'S') {
                    //fm.alert('上传成功');
                    window.location.href = "/Base/BusBooking/buyTicket/apply_id/{BEESCRM:$apply_id}/start/"+address1+"/end/"+address2+"/time/"+time;
                } else {
                    fm.alert('暂无可预订班次');
                }
            }
        })

    })

    $(function () {

        $('#time').mobiscroll().date({
            theme: 'android-holo-light',//皮肤样式
            lang: 'zh',//中文
            display: 'bottom',//位于底部
            dateFormat: 'yyyy-mm-dd',//格式
            endYear: 2099,
        });

        $('#time').mobiscroll().date({
            theme: 'android-holo-light',//皮肤样式
            lang: 'zh',//中文
            display: 'bottom',//位于底部
            dateFormat: 'yyyy-mm-dd'//格式
        });
        var close_time={BEESCRM:$close_time};//后天设置的购票时间
        var endDate = new Date();
        endDate.setDate(endDate.getDate()+close_time);

        var startDate = new Date();
        startDate.setDate(startDate.getDate()+1);
        var opt={};
        opt.date = {preset : 'date'};
        opt.default = {
            theme: 'android-holo-light', //皮肤样式
            display: 'bottom', //显示方式
            mode: 'scroller', //日期选择模式
            dateFormat: 'yyyy-mm-dd',//格式
            lang:'zh',
            min: startDate,
            max: endDate
        };

        var optDateTime = $.extend(opt['date'], opt['default']);
        $("#time").mobiscroll(optDateTime).date(optDateTime);

    });


    $('.head-img').click(function () {
        $(this).nextAll('.upload-img').click();
    });
    function reload() {
        setTimeout('location.reload()', 2000);
    }
</script>
</html>